
import flash.net.SharedObject;
import flash.xml.XMLDocument;

import mx.containers.ViewStack;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
private var vs:ViewStack;
private var remote_check_login:RemoteObject = new RemoteObject("Login");
private var mySO:SharedObject;

public function login_reset():void
{
}

public function init():void
{
    vs = this.parent as ViewStack;
}

public function getChild(str:String):Object
{
    for each (var obj:Object in vs.getChildren())
    {
        if (obj.name === str)
        {
            break;
        }
    }
    return obj;
}

public function login_check(userName:String , pass:String):void
{
    if (null == userName || null == pass)
    {
        Alert.show("ユーザＩＤまたは、パスワードが間違っています。 ");
    }
    else
    {
        remote_check_login.addEventListener(FaultEvent.FAULT , login_false);
        remote_check_login.addEventListener(ResultEvent.RESULT , login_success);
        remote_check_login.check_login(userName , pass);
    }
}

public function login_false(event:FaultEvent):void
{

}

public function login_success(event:ResultEvent):void
{
    if (event.result)
    {
        var obj:Object = getChild("user_view");
        vs.selectedChild = obj as Canvas;
    }
    else
    {
        Alert.show("ユーザIDまたはパスワードが間違いました。");
    }
}